689C - Mike and Chocolate Thieves - CodeForces Solution


binary search combinatorics math *1700

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define N 100005
using namespace std;
vector<int>adj[N];
int fun(int n){
      int sum = 0;
      for(int r = 2; r<=cbrt(n); r++){
            sum += (n/(r*r*r));
      }
      return sum;
}
int32_t main(){
           int m;
           cin>>m;
           
           int res = -1;
           int low = 1;
           int high = 1e18;
           while(low<=high){
                 int mid = (low+high)/2;
                 if(fun(mid)==m)
                  {
                        res = mid;
                        high = mid-1;
                  }
                  else if(fun(mid) > m){
                        high = mid-1;
                  }
                  else
                        low = mid+1;
           }
           
           cout<<res<<endl;
        }
        
    
   // 1 + 1 + 2 + 4 + 8
  


Comments

Submit
0 Comments
More Questions

221A - Little Elephant and Function
492C - Vanya and Exams
1369B - AccurateLee
892B - Wrath
999A - Mishka and Contest
727C - Guess the Array
1625C - Road Optimization
1715D - 2+ doors
267A - Subtractions
1582A - Luntik and Concerts
560A - Currency System in Geraldion
946A - Partition
1068B - LCM
1692E - Binary Deque
679A - Bear and Prime 100
488A - Giga Tower
14A - Letter
1150A - Stock Arbitraging
1552A - Subsequence Permutation
1131F - Asya And Kittens
1475F - Unusual Matrix
133B - Unary
1547A - Shortest Path with Obstacle
624A - Save Luke
1238A - Prime Subtraction
1107C - Brutality
1391B - Fix You
988B - Substrings Sort
312A - Whose sentence is it
513A - Game